package com.kb.design.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kb.design.common.ApiResponse;
import com.kb.design.common.ResponseObject;
import com.kb.design.dto.ForestallOrderDTO;
import com.kb.design.entity.DesignDictData;
import com.kb.design.entity.DesignDictType;
import com.kb.design.entity.DesignRole;
import com.kb.design.entity.QaCheckDict;
import com.kb.design.service.DesignDictService;
import com.kb.design.service.QaCheckDictService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;;
import java.util.List;
import java.util.Map;

/**
 * @Auther:chenzx
 * @Date:2024-02-23
 * @Description:字典
 */
@RestController
@RequestMapping("dict")
public class DesignDictController {


    @Resource
    private DesignDictService designDictService;
    @Resource
    private QaCheckDictService qaCheckDictService;

    /**
     *
     *
     * @param
     * @return qa新增
     */
    @PostMapping("qaInsert")
    public ApiResponse insert(@RequestBody QaCheckDict qaCheckDict) {
        qaCheckDictService.insert(qaCheckDict);
        return ApiResponse.success("保存成功");
    }
    /**
     *
     *
     * @param
     * @return qa编辑
     */
    @PostMapping("qaUpdate")
    public ApiResponse qaUpdate(@RequestBody QaCheckDict qaCheckDict) {
        qaCheckDictService.qaUpdate(qaCheckDict);
        return ApiResponse.success("保存成功");
    }
    /**
     *
     *
     * @param
     * @return qa删除
     */
    @PostMapping("qaDel")
    public ApiResponse qaDel(@RequestBody QaCheckDict qaCheckDict) {
        qaCheckDictService.qaDel(qaCheckDict);
        return ApiResponse.success("保存成功");
    }
    /**
     *
     *
     * @param
     * @return qa列表
     */
    @PostMapping("queryQaList")
    public ApiResponse queryQaList(@RequestBody QaCheckDict qaCheckDict) {
        Page<QaCheckDict> page = new Page<>(qaCheckDict.getPage(), qaCheckDict.getPerPage());
        ResponseObject responseObject = new ResponseObject();
        Page<QaCheckDict> list = qaCheckDictService.queryList(page, qaCheckDict);
        responseObject.setItems(list.getRecords());
        responseObject.setTotal(list.getTotal());

        return ApiResponse.success(responseObject);
    }
    /**
     *
     *
     * @param
     * @return 获取个人qa检查列表
     */
    @PostMapping("getGroupedByProjectAndType")
    public ApiResponse getGroupedByProjectAndType(@RequestBody QaCheckDict qaCheckDict) {
        ResponseObject responseObject = new ResponseObject();
        //判断是否有草稿 有查询草稿 无查询配置
        boolean draft = qaCheckDictService.draft(qaCheckDict);
        List<Map<String, Object>> groupedByProjectAndType;
        if (draft){
            groupedByProjectAndType = qaCheckDictService.getDraft(qaCheckDict);
        }else {
            groupedByProjectAndType = qaCheckDictService.getGroupedByProjectAndType(qaCheckDict);
        }

        responseObject.setItems(groupedByProjectAndType);
        return ApiResponse.success(responseObject);
    }
    /**
     *
     *
     * @param
     * @return 新增
     */
    @PostMapping("insert")
    public ApiResponse insert(@RequestBody DesignDictType designDictType) {
        return ApiResponse.success(designDictService.insert(designDictType));
    }

    /**
     *
     *
     * @param
     * @return 新增
     */
    @PostMapping("insertDictData")
    public ApiResponse insertDictData(@RequestBody DesignDictData designDictData) {
        return ApiResponse.success(designDictService.insertDictData(designDictData));
    }
    /**
     *
     *
     * @param
     * @return del
     */
    @GetMapping("delDictType")
    public ApiResponse delDictType(String type) {
        return ApiResponse.success(designDictService.delDictType(type));
    }

    /**
     *
     *
     * @param
     * @return 查询字典数据
     */
    @PostMapping("queryDictByType")
    public ApiResponse queryDictByType(@RequestBody DesignDictData designDictData) {
        return ApiResponse.success(designDictService.queryDictByType(designDictData));
    }
}
